package net.okjsp.poll;

import java.util.ArrayList;

public class PollService {
	
	static ArrayList<Poll> list = new ArrayList<Poll>();

	public int add(Poll poll) {
		int newPollId = list.size();
		poll.setId(newPollId);
		list.add(poll);
		return poll.getId();
	}

	public ArrayList<Poll> getList() {
		return list;
	}

	public Poll get(int id) {
		for(Poll poll: list) {
			if (poll.getId() == id) 
				return poll;
		}
		return null;
	}
	
	public int countUp(int pollId, int itemId) {
		Poll poll = get(pollId);
		return poll.increment(itemId);
	}
}
